<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right" style="box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);line-height: 3;padding-left: 1em;">
      <el-breadcrumb-item>系统管理</el-breadcrumb-item>
      <el-breadcrumb-item>更换手机号</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="modify" v-if="dandh">
      <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="手机号" prop="mobile">
          <el-input v-model="ruleForm.mobile"></el-input>
        </el-form-item>
        <el-form-item label="验证码" prop="testingCode">
          <el-input v-model="ruleForm.testingCode"  style="width: 70%;"></el-input>
          <el-button type="primary">获取验证码</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="modify" v-if="!dandh">
      <el-page-header @back="goBack" content="更换新手机号" style="color: #3A8EE6;padding: 10px 0;margin-bottom: 20px;"></el-page-header>
      <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="新手机号" prop="mobile">
          <el-input v-model.number="ruleForm.mobile" placeholder="请输入内容"></el-input>
        </el-form-item>
        <el-form-item label="验证码" prop="testingCode">
          <el-input v-model="ruleForm.testingCode"  style="width: 70%;" placeholder="请输入内容"></el-input>
          <el-button type="primary">获取验证码</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
  export default {
    data() {
       var checkAge = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('手机号不能为空'));
        }
        setTimeout(() => {
          if (!Number.isInteger(value)) {
            callback(new Error('请输入数字值'));
          } else {
            if (!(/^1[34578]\d{9}$/.test(value))) {
              callback(new Error('请输入正确手机号'));
            } else {
              callback();
            }
          }
        }, 1000);
      };
      var validatePass2 = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入验证码'));
        }  else {
          callback();
        }
      };
      return {
        dandh:true,
        ruleForm: {
          pass: '',
          testingCode: '',
          mobile:''
        },
        rules: {
          testingCode: [{
            required: true,
            validator: validatePass2,
            trigger: 'blur'
          }],
          mobile: [{
            required: true,
            validator: checkAge,
            trigger: 'blur'
          }]
        }
      };
    },
    methods: {
      submitForm(formName) {
        this.dandh = false;
        this.$refs[formName].validate((valid) => {
          if (valid) {
            alert('submit!');
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },
      goBack() {
        this.dandh = true;
      }
    }
  }
</script>

<style scoped="scoped">
  .modify {
    width: 700px;
    height: 230px;
    margin: 30px;
    padding: 30px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, .5), 0 0 6px rgba(0, 0, 0, .04);
  }
  /deep/ .el-page-header__content {
    font-size: 16px;
  }
</style>
